<?php 
/**
 * 内容页显示控制器
 * @author 杨帆
 */
class CommentController extends ShopCarController{
    /**
     * 默认显示
     */
    public function index(){
       //显示头部公用数据
       $this->commonShow();
       //接入商品主键
       $gid = Q('get.gid',0,'intval');
       //商品主数据表数据
       $goodsData = M('goods')->where("gid={$gid}")->find();
       $this->assign('goodsData',$goodsData);
       //商品明细表数据
       $gEntryData = M('goods_entry')->where("goods_gid={$gid}")->find();
       //对$gEntryData['shop_pic']字段数据进行反序列化处理；
       $gEntryData['shop_pic'] = unserialize($gEntryData['shop_pic']);
       //在common控制器中的getpic方法中进行处理，并重新赋值给$gEntryData['shop_pic']；
       $gEntryData['shop_pic'] = $this->getPic($gEntryData['shop_pic']);
       //分配数据到前台
       $this->assign('gEntryData',$gEntryData);
       //商品规格数据
       //查询该商品的属性表中,共有几个规格属性,全部输出;
       $goodsAttrDate = M()->join('__attribute__ AS at JOIN __goods_attr__ AS ga ON at.attrid=ga.attrid')->where("at.type=2 and goods_gid={$gid}")->group('at.title')->order('at.attrid')->all();
       //循环
       foreach ($goodsAttrDate as $k => $v) {
            //对该商品每一个属性中的attr字段,压入属于该商品及这个属性的所有属性值,最终形成一个二维数组;注意$k的使用;
           	$goodsAttrDate[$k]['attr'] = M('goods_attr')->where("goods_gid={$gid} AND attrid={$v['attrid']}")->all();
       }
       $this->assign('goodsAttrDate',$goodsAttrDate);
       //商品属性数据
       //查询该商品的属性表中,全部的属性数据并输出;
       $goodsAttrData1=M()->join('__attribute__ AS at JOIN __goods_attr__ AS ga ON at.attrid=ga.attrid')->where("at.type=1 and goods_gid={$gid}")->order('at.attrid')->all();
       $this->assign('goodsAttrData1',$goodsAttrData1);
//     p($_SESSION);
       //购物车的总金额及数量
       $totalprice = Cart::getTotalPrice();
       $this->assign('totalprice',$totalprice);
       $totlaNums = Cart::getTotalNums();
       $this->assign('totlaNums',$totlaNums);
       $this->display(); 
      
    }
    /**
     * 商品规格的问题
     */
    public function attrGetData(){
        if(IS_AJAX){
            //规格id
            $id = Q('post.id');
            //商品id
            $gid = Q('post.gid',0,'intval');
            //去掉id的最后一个逗号;
            $id = (substr($id,0,strlen($id)-1));
            //查询该商品该规格的现有列表库存;
            $goodsListData = M('goods_list')->where("gaid='{$id}' and goods_gid={$gid}")->getfield('fqty');
            if($goodsListData){
                echo json_decode($goodsListData);exit;
            }else{
                echo 0;exit;
            }  
        }
    }
 }
 
 
 
 
 
 
 
 
 
 
 




 ?>